package com.cskaoyan.market.controller;

import com.cskaoyan.market.constrain.LegalOrder;
import com.cskaoyan.market.constrain.LegalSort;
import com.cskaoyan.market.constrain.MarketAdminConflictUsername;
import com.cskaoyan.market.db.domain.MarketAdmin;
import com.cskaoyan.market.group.Create;
import com.cskaoyan.market.group.Update;
import com.cskaoyan.market.service.AdminAdminService;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author lixianbiao
 * @since 2024/06/28 19:18
 */
@RestController
@RequestMapping("admin/admin")
@Validated
public class AdminAdminController {
    @Autowired
    private AdminAdminService adminAdminService;

    @GetMapping("list")
    public Object list(@NotNull int page,@NotNull int limit, @LegalSort({"add_time"}) String sort, @LegalOrder String order, String username){
        List<MarketAdmin> adminList = adminAdminService.list(page,limit,sort,order,username);
        return ResponseUtil.okList(adminList);
    }

    @PostMapping("create")
    public Object creat(@Validated({Create.class}) @NotNull @MarketAdminConflictUsername  @RequestBody MarketAdmin admin){
        adminAdminService.create(admin);
        return admin;
    }
}